package com.zls.controller;

import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.page.Result;
import com.zls.pojo.TFarm;
import com.zls.pojo.TTask;
import com.zls.service.TFarmService;
import com.zls.service.TTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("ttask")
@RestController
public class TTaskController {
    @Autowired
    private TTaskService tTaskService;
    @GetMapping("findAll")
    public List<TTask> findAll(){
        List<TTask> all = tTaskService.list();
        return all;
    }
    /**
     * 用户列表分页查询
     */
    @PostMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPageBean){
        PageResult page = tTaskService.findPage(queryPageBean);
        return page;
    }

    /**
     * 用户添加
     * @param tFarm
     * @return
     */
//    @PostMapping("add")
//    public Result add(@RequestBody TFarm tFarm){
//        int i = tFarmService.addFTarm(tFarm);
//        if (i>0){
//            return Result.success();
//        }else {
//            return Result.fail();
//        }
//    }

    /**
     * 根据id查
     * @param id
     * @return
     */
    @GetMapping("findById")
    public Result findById(@RequestParam("id") int id){
        TTask byId = tTaskService.getById(id);
        Result result=new Result();
        if (byId!=null){
            result.setData(byId);
            result.setFlag(true);
        }else {
            result.setMessage("系统错误");
        }
        return result;
    }

    /**
     * 修改
     * @param tTask
     * @return
     */
    @PostMapping("edit")
    public Result edit(@RequestBody TTask tTask){
        int i = tTaskService.editTTask(tTask);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    @PostMapping("edits")
    public Result edits(@RequestBody TTask tTask){
        int i = tTaskService.editTTasks(tTask);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    @GetMapping("delete")
    public Result delete(@RequestParam("id") int id){
        boolean i = tTaskService.removeById(id);
        if (i){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

}
